package com.neu.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.neu.pojo.Patient;
import com.neu.pojo.Result;
import com.neu.pojo.Worker;
import com.neu.service.impl.ResultService;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;

public class SuggestionGive extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SuggestionGive frame = new SuggestionGive(new Worker(),new Patient(),new Result());
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SuggestionGive(Worker w,Patient p,Result r) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 425, 302);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("请给出您的建议");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(137, 25, 144, 15);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(46, 47, 327, 131);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("确定");
		btnNewButton.setBounds(160, 205, 97, 23);
		contentPane.add(btnNewButton);
		btnNewButton.addActionListener((e)->{
			r.setSuggestion(textField.getText());
			if(ResultService.getInstance().record(r)) {
				JOptionPane.showMessageDialog(null, "记录成功");//提示
			}else {
				JOptionPane.showMessageDialog(null, "记录失败");//提示
			}
			new EvaluateUI(w, p).setVisible(true);//跳转新窗口
			setVisible(false);
		});
		
		//窗口居中
		setLocationRelativeTo(null);
	}
}
